package frist50;

import org.junit.jupiter.api.Test;

public class T0035 {
    public int searchInsert(int[] nums, int target) {
        int right = find(nums, target, true, true);
        return right;


    }

    public int find(int[] nums, int target, boolean isEque, boolean symbol) {
        int left = 0, right = nums.length - 1;
        int ans = nums.length;
        while (left <= right) {
            int mod = left + (right - left) / 2;
            if (nums[mod] > target || isEque && nums[mod] == target) {
                right = mod - 1;
                if (symbol) ans = mod;
            } else {
                left = mod + 1;
                if (!symbol) ans = mod;
            }
        }
        return ans;
    }

    @Test
    public void test() {

        int[] ints = {5, 7, 8};
        int re = searchInsert(ints, 1);
        System.out.println(re);
    }
}
